//
//  ContentViewController.m
//  HandWork
//
//  Created by 王阳阳 on 16/1/25.
//  Copyright © 2016年 www.lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "ContentViewController.h"
#import "MyLoopsView.h"
#import "FirstContentModel.h"
#import "UMSocial.h"
@interface ContentViewController ()<UIScrollViewDelegate,UMSocialUIDelegate>
@property (nonatomic, retain)UILabel *content;//内容
@property (nonatomic, retain)UILabel *titlename;//标题
@property (nonatomic, retain)UIImageView *img;//图片
@property (nonatomic, retain)NSMutableArray *dataarr;//数组
@end

@implementation ContentViewController
- (void)dealloc
{
    [_mid release];
    [_content release];
    [_titlename  release];
    [_img release];
    [_dataarr release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
//  [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)forBarMetrics:UIBarMetricsDefault];//导航条返回键带的首页 让他消失
    //收藏
    
    UIBarButtonItem *collect = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"collect"] style:UIBarButtonItemStylePlain target:self action:@selector(collect)];
    
    UIBarButtonItem *fenxiang = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"fenxiang"] style:UIBarButtonItemStylePlain target:self action:@selector(fenxiang)];
    self.navigationItem.rightBarButtonItems = @[collect, fenxiang];
    
    
    [self data];//数据
    [self create];//内容
    
    
}
#pragma mark - 数据解析
- (void)data
{
    NSString *str = [[@"http://m.shougongke.com/index.php?c=HandClass&a=info&id=" stringByAppendingString:self.mid]stringByAppendingString:@"&vid=15"];
    [AFNnetWork GETwithURL:str completion:^(id result) {
        NSDictionary *dic = result[@"data"];
        
        self.content.text = [dic objectForKey:@"content"];//内容
        self.titlename.text = [dic objectForKey:@"subject"];//标题
//        [self.img sd_setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"host_pic_s"]]];//图片
        NSArray *arr = result[@"data"][@"pic"];
        //轮播图
        MyLoopsView *scroll = [MyLoopsView myLoopsViewWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 250) imageArr:arr];
        scroll.block = ^(NSInteger index){
                
        };
            
        [self.view addSubview:scroll];
    }];
}
-(void)create
{
    //scrollView
    UIScrollView *scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 314, [UIScreen mainScreen].bounds.size.width, 1000)];
    //内容
    scroll.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 1500);
    //代理人
    scroll.delegate = self;
    [self.view addSubview:scroll];
    //标题
    self.titlename = [[UILabel alloc]initWithFrame:CGRectMake(5, -50, [UIScreen mainScreen].bounds.size.width - 10, 30)];
    //添加
    [scroll addSubview:self.titlename];
    [_titlename release];
    
    
//    CGFloat h1 = [[self class] heightWihtText:_content.text];
    self.content = [[UILabel alloc]initWithFrame:CGRectMake(5,0, [UIScreen mainScreen].bounds.size.width - 10,  300)];
    self.content.numberOfLines = 0;
    self.content.font = [UIFont systemFontOfSize:14];
//    self.content.backgroundColor = [UIColor grayColor];
    self.content.textColor = [UIColor grayColor];
    
    [scroll addSubview:_content];
    
//    self.img = [[UIImageView alloc]initWithFrame:CGRectMake(0, self.content.frame.size.height + self.content.frame.origin.y , [UIScreen mainScreen].bounds.size.width, 200)];
//    [scroll addSubview:self.img];
    
    [_content release];
//    [_img release];
    [scroll release];
    
    
    
}
#pragma mark - 自适应文字高度
+ (CGFloat)heightWihtText:(NSString *)text
{
    // 1.文本属性
    NSDictionary *dic = @{NSFontAttributeName: [UIFont systemFontOfSize:14]};
    // 2.预计尺寸
    CGSize s = CGSizeMake(375 - 10, 1000);
    // 3.计算
    CGRect r = [text boundingRectWithSize:s options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return r.size.height;
}
- (void)fenxiang
{
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:@"56a87643e0f55a9fc20020c2"
                                      shareText:@"你要分享的文字"
                                     shareImage:[UIImage imageNamed:@"icon.png"]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToWechatSession,UMShareToQQ,nil]
                                       delegate:self];
}
#pragma mark - 收藏
- (void)collect
{
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
